<script setup>
import {ref,onMounted} from 'vue'
import RecommendGoodsCard from "@/components/card/recommendGoodsCard.vue";
import {getCategoriesAPI} from "@/apis/home.js";
import {useCategoryStore} from "@/stores/category.js";
import router from "@/router/index.js";

const item=ref({
  imgUrl:'https://yanxuan-item.nosdn.127.net/2269a4a0b26a532b430c3fb6e93b83eb.png',
  title:'西班牙特级初榨橄榄油750ml',
  g_price:'999.99'
})

const categories=ref([])
const goods=ref(null)

const getCategories=async ()=>{
  if(useCategoryStore().isEmpty) {
    await useCategoryStore().getCategories()
  }
  categories.value = useCategoryStore().categories
}

//挂载完成时发送请求
onMounted(()=>{
  getCategories()
})


//获取图标路径
function getImageUrl(imageName) {
  return new URL(`../assets/img/${imageName}`, import.meta.url).href
}

const toCategory = (category) => {
  if (!category) {
    console.error('分类参数不能为空')
    return
  }
  router.push(`/category/${category}`)
}

</script>

<template>
  <div class="product-class">

    <ul class="categoryUL">

      <li v-for="(item ,index) in categories" :key="index">
        <img src="@/assets/img/apple.png"  align="texttop" class="goods-icon" alt="">


          <span class="categoryName" @click="toCategory(item.FirstCategory)"
                style="font-size: 16px">{{ item.FirstCategory }}</span>
          <span class="categoryName" @click="toCategory(category)"
                v-for="category in item.SecondCategory">&nbsp{{category}}&nbsp</span>


        <div class="goodsPanel slideInLeft" style="top: 1px;">
          <div class="goodsArea">
            <div class="titleArea">
              <span style="font-size: 20px;line-height:80px;color: #333333">分类推荐 </span>
              <span style="font-size: 16px;color: #a5a8ab"> 根据您的购买或浏览记录推荐</span>
            </div>

            <el-empty v-show="goods===null" description="暂无数据"/>

            <div class="dataArea">
              <recommend-goods-card v-show="goods !==null" v-for="x in 6" :item="item"></recommend-goods-card>
            </div>
          </div>
        </div>
      </li>

<!--      <li >-->
<!--        <img src="@/assets/img/9-1.png"  align="texttop" class="goods-icon" alt="">-->
<!--        <span class="title">蔬菜</span> 葱姜蒜类 叶菜类 食用菌-->
<!--        <div class="goodsPanel slideInLeft" style="top:-51px;overflow: hidden;">-->
<!--          <el-empty description="No Data" />-->
<!--        </div>-->
<!--      </li>-->

<!--      <li>-->
<!--        <img src="@/assets/img/4-1.png" align="texttop" class="goods-icon" alt="">-->
<!--        <span class="title">种子种苗</span> 水果种苗 蔬菜种子-->
<!--        <div class="goodsPanel slideInLeft" style="top:-101px">-->


<!--        </div>-->
<!--      </li>-->

<!--      <li>-->
<!--        <img src="@/assets/img/6-1.png" align="texttop" class="goods-icon" alt="">-->
<!--        <span class="title">日用百货</span> 纸品湿巾 厨房用品-->
<!--        <div class="goodsPanel slideInLeft" style="top:-151px"></div>-->
<!--      </li>-->

<!--      <li>-->
<!--        <img src="@/assets/img/meat.png" align="texttop"  class="goods-icon" alt="">-->
<!--        <span class="title">禽畜肉蛋</span> 肉类 蛋类 活畜-->
<!--        <div class="goodsPanel slideInLeft" style="top:-201px"></div>-->
<!--      </li>-->

<!--      <li>-->
<!--        <img src="@/assets/img/fish.png" align="texttop" class="goods-icon" alt="">-->
<!--        <span class="title">水产</span> 食用鱼类 贝类 虾类-->
<!--        <div class="goodsPanel slideInLeft" style="top:-251px"></div>-->
<!--      </li>-->

<!--      <li >-->
<!--        <img src="@/assets/img/rice.png" align="texttop" class="goods-icon" alt="">-->
<!--        <span class="title">中药材</span> 滋补药材 树叶类-->
<!--        <div class="goodsPanel slideInLeft" style="top:-301px"></div>-->
<!--      </li>-->

<!--      <li >-->
<!--        <img src="@/assets/img/5-1.png" align="texttop" class="goods-icon" alt="">-->
<!--        <span class="title">农资农机</span> 肥料 农药 饲料-->
<!--        <div class="goodsPanel slideInLeft" style="top:-351px"></div>-->
<!--      </li>-->
    </ul>
  </div>




</template>


<style scoped>
.product-class {
  box-shadow: 0 0 5px 0 rgba(144, 144, 144, 0.29);
  margin: 20px 20px 20px 0;
  height: 400px;
  width: 250px;
  border-radius: 5px;
  padding: 1px;
  background-color: rgb(255, 255, 255);
  z-index: 1;
  position: relative;
}

.goodsPanel{
  display: none;
  position: absolute;
  z-index: -1;
  top: -1px;
  left: 249px;
  width: 670px;
  height: 400px;
  background-color: rgb(255, 255, 255);
  /* x偏移量 | y偏移量 | 阴影模糊半径 | 阴影扩散半径 | 阴影颜色 */
  box-shadow: 8px 0 5px 0 rgba(144, 144, 144, 0.29);
  border-radius: 5px;
  padding: 0 0 0 20px;
}

.goodsArea{
  display: flex;
  flex-direction: column;
  cursor: default;
}

.titleArea{
 max-width: 300px;
  height: 80px;
  overflow: hidden;
}

.dataArea{
  max-width: 640px;
  height: 310px;
  overflow: hidden;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: space-between;
  gap: 20px;
  padding: 10px;
}

li:hover>div[class]{
  display: block;
}

li{
  line-height: 50px;
}

.goods-icon{
  height: 20px;
  width: 20px;
  margin-right: 5px;
}
.categoryName:hover{
  color: #fff566;
}

.categoryUL{
  list-style: none;
  color: #333333;
  padding-left: 0;
  margin: 0;
  font-family: "Microsoft YaHei",serif;
  justify-content: center;
}

.categoryUL li{
  height: 50px;
  font-size: 14px;
  padding-left: 20px;
  margin: 0 auto;
}

.categoryUL li:hover{
  box-shadow: 0 0 5px 0 rgba(7, 203, 41, 0.76);
  background-color: rgba(7, 203, 41, 0.76);
  color: white;
  cursor:pointer;
}

.goodsPanel{
  animation-duration: 1.2s ;
  animation-fill-mode: both ;
}

@keyframes slideInLeft {
  from {
    width: 100px;
    transform: translate3d(-10px, 0, 0) ;
    visibility: visible;
  }

  to {
    width: 670px;
    transform: translate3d(-10px, 0, 0);
  }
}

.slideInLeft {
  animation-name: slideInLeft;
}
</style>

